<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
    .box1 {
      background-color: aquamarine;
      width: 100px;
      height: 50px;
      display: grid;
      place-items: center;
      cursor: move;
      user-select: none;

      /* 处理所有触摸操作 */
      /* touch-action: auto; */

      /* 禁止平移和缩放 */
      touch-action: none;

      /* 禁止平移 */
      /* touch-action: pan-x; */
      /* touch-action: pan-y; */

      /* 只允许进行滚动和持续缩放操作，不允许双击缩放 */
      /* touch-action: manipulation; */

    }
  </style>
</head>

<body>
  <div class="box1">拖动</div>

  <script>
    let startX = 0
    let isMoveing = false;
    const box1 = document.querySelector('.box1');








    /**PC mousedown**/
    // function down(e) {
    //   e.preventDefault();
    //   isMoveing = true;
    //   document.addEventListener('mousemove', move);
    //   document.addEventListener('mouseup', up);
    //   console.log('==down====>', e)
    // }



    // function move(e) {
    //   e.preventDefault();
    //   if (!isMoveing) return
    //   console.log('==move====>', e)
    // }

    // function up(e) {
    //   e.preventDefault();
    //   isMoveing = false;
    //   document.removeEventListener('mousemove', move);
    //   document.removeEventListener('mouseup', up);
    //   console.log('==up====>', e)
    // }

    // box1.addEventListener('mousedown', down);





    /**PC  H5 pointerdown**/
    function pointerdown(e) {
      // e.preventDefault();
      isMoveing = true;
      startX = e.pageX - startX
      console.log('pointer-down', startX);
    }

    function pointermove(e) {
      box1.setPointerCapture(e.pointerId);
      // e.preventDefault();
      if (!isMoveing) return;
      let newDx = e.pageX - startX;
      console.log('pointer-move', newDx);
      box1.style.transform = `translate3d(${newDx}px, 0, 0)`;
    }
    function pointerup(e) {
      console.log('pointer-up', e);
      isMoveing = false;
      startX = 0
    }
    box1.addEventListener('pointerdown', pointerdown);
    box1.addEventListener('pointermove', pointermove);
    box1.addEventListener('pointerup', pointerup);






    // function touchstart(e) {
    //   isMoveing = true;
    //   startX = e.touches[0].pageX - startX
    //   console.log('==touchstart====>', e)
    // }

    // function touchmove(e) {
    //   console.log('==touchmove====>', e)
    //   if (!isMoveing) return;
    //   let newDx = e.touches[0].pageX - startX;
    //   box1.style.transform = `translate3d(${newDx}px, 0, 0)`;

    // }

    // function touchend(e) {
    //   console.log('==touchend====>',)
    //   isMoveing = false;
    //   startX = 0

    // }

    // box1.addEventListener('touchstart', touchstart);
    // box1.addEventListener('touchmove', touchmove);
    // box1.addEventListener('touchend', touchend);




    // (function () {


    //   try {
    //     a

    //   } catch (error) {
    //     console.log('===error==>',)

    //   } finally {

    //     console.log('==finally===>',)

    //   }
    //   console.log('==主线代码====>',)

    // })()









  </script>
</body>

</html>